package com.s63.modules.rabbit;

import com.s63.entity.User;
import com.s63.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.s63.modules.rabbit.RabbitConfig.NAME_QUEUE_USER_CREATED;

@Component
@Slf4j
public class MqConsumer {
    @Autowired
    private IUserService userService;

    @RabbitListener(queues = NAME_QUEUE_USER_CREATED)
    public void handleUserCreate(User user) {
        log.info("收到创建用户消息：{}", user);
        userService.save(user);
        log.info("异步保存用户成功:{}", user);
    }
}
